// pages/my_poster/my_poster.js
const app = getApp()
const Host = require('../../config').Host
Page({

    /**
     * 页面的初始数据
     */
    data: {
        poster_bg:'',
        code_img:'',
        successShow:false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var that=this;
        var openid = wx.getStorageSync('openid');
        wx.request({
          url: Host + 'Mine/share',
          data: { openid },
          method: 'post',
          header: { 'content-type': 'application/x-www-form-urlencoded' },
          success: function (res) {
            that.setData({
              share: res.data,
              poster_bg: res.data.share_bg,
              code_img: res.data.shareCode,
            });
            if (that.data.poster_bg && that.data.code_img) {
              that.setData({
                successShow: true,
              })
            }
          },
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
      var that = this

      var user_id = that.data.share.user_id;
      var title = that.data.share.sharename;
      var imageUrl = that.data.share.shareimg;
      wx.showShareMenu({
        withShareTicket: true
      })
      
      return {
        title: title,
        path: '/pages/index2/index2?pid=' + user_id,
        imageUrl: imageUrl,
        success: function (res) {
          //console.log(res)
          // 转发成功
        },
        fail: function (res) {
          // 转发失败
        }
      }

    }
})